package com.aaa.cs.controller;

import com.aaa.cs.entity.CarInsurance;
import com.aaa.cs.service.CarInsuranceService;
import com.aaa.common.constants.ExceptionConstant;
import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import com.aaa.cs.entity.CarInsurance;
import com.aaa.cs.service.CarInsuranceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CarInsurance)表控制层
 *
 * @author makejava
 * @since 2020-11-18 22:10:48
 */
@RestController
@RequestMapping("carInsurance")
public class CarInsuranceController {
    /**
     * 服务对象
     */
    @Resource
    private CarInsuranceService carInsuranceService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Result selectOne(Integer id) {
        //当ID为空时抛出自定义异常
        if (null==id){
            throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                    ExceptionConstant.ID_NOT_NULL.getErrorMessage());
        }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.carInsuranceService.queryById(id));
    }

    /**
     * 新增条数
     * @param carInsurance
     * @return
     */
    @PostMapping("insertCarInsurance")
    public Result insertCarInsurance (@RequestBody CarInsurance carInsurance ){
        return new Result(ReturnCode.SUCCESSS.getCode(), ReturnCode.SUCCESSS.getMsg()
        ,carInsuranceService.insert(carInsurance));
    }


    /**
     * 分页外加条件查询
     * @param pageNo
     * @param pageSize
     * @param carInsurance
     * @return
     */
    @GetMapping("queryAll")
    public Result queryPageByParam(Integer pageNo, Integer pageSize, CarInsurance carInsurance){
        return carInsuranceService.queryPageByParam(pageNo,pageSize,carInsurance);
    }
//    @GetMapping("insertOrUpdateBatch")
//    public int insertOrUpdateBatch(CarInsurance carInsurance){
//        return carInsuranceService.insert(carInsurance);
//    }
//    @GetMapping("deleteById")
//    public boolean deleteById(Integer id){
//        return carInsuranceService.deleteById(id);
//    }
//    @GetMapping("update")
//    public CarInsurance update(CarInsurance carInsurance){
//        return carInsuranceService.update(carInsurance);
//    }


    /**
     * 修改数据
     * @param carInsurance
     * @return
     */
    @PutMapping("updateCarInsurance")
    public Result updateCarInsurance(@RequestBody CarInsurance carInsurance){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),carInsuranceService.update(carInsurance));
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteCarInsurance")
    public Result deleteCarInsurance(Integer id){
        //当ID为空时抛出自定义异常
        if (null==id){
            throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                    ExceptionConstant.ID_NOT_NULL.getErrorMessage());
        }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),carInsuranceService.deleteById(id));
    }





}